package com.meisupic.copyright.support.security;


import java.net.URLEncoder;
import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
import org.springframework.security.authentication.encoding.PasswordEncoder;

/**
 * @author lanjian
 * @version V1.0
 * @Description: TODO
 * @date 2018/2/7 22:04
 */
public class CustomPasswordEncode implements PasswordEncoder {


  @Override
  public String encodePassword(String rawPass, Object salt) {
    Md5PasswordEncoder md5PasswordEncoder = new Md5PasswordEncoder();
    String passUrlEncode = URLEncoder.encode(rawPass);
    String encPass = md5PasswordEncoder.encodePassword(passUrlEncode,null);
    encPass = md5PasswordEncoder.encodePassword(encPass+salt,null);
    return encPass;
  }

  @Override
  public boolean isPasswordValid(String encPass, String rawPass, Object salt) {
    return encodePassword(rawPass,salt).equals(encPass);
  }
}
